﻿@using OSBLE.Models

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "Suggestions Settings";
    bool ShowSuggestionsWindow = ViewBag.ShowSuggestionsWindow ?? true;
    int RefreshThreshold = ViewBag.RefreshThreshold ?? 10;
}

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/interventions.css")?version=1.0" />
<script type="text/javascript" src="@Url.Content("~/Scripts/Interventions.js")?version=1.01"></script>
@Html.Partial("_UserFeedbackPrompt", new ViewDataDictionary { { "interventionId", -6 } })
<div style="float: left;">    
    <h2>Suggestions Settings</h2>
    <em>Note: In-IDE settings will be updated upon logging into the VS Plugin. Please restart Visual Studio after updating IDE specific settings.</em>
    <h5>IDE Specific Settings</h5>
    <p style="text-indent: 25px;">
        <input type="checkbox" value="True" id="enable-suggestions-ide" name="ShowSuggestionsWindow" @if (ShowSuggestionsWindow) { <text> checked="checked" </text>     } />
        <text">Show the OSBLE+ suggestions window in the IDE.</text>        
    </p>

    <h5>Global Settings (IDE and Dashboard)</h5>
    <p style="text-indent: 12.5px;">        
        @Html.Label("Time before refreshing suggestions: ", new { id = "suggestion-refresh-label" })
        @{
            List<SelectListItem>
                listItems = new List<SelectListItem>
                    ();
            listItems.Add(new SelectListItem
            {
                Text = "Show Immediately",
                Value = "0",
            });
            listItems.Add(new SelectListItem
            {
                Text = "5 Minutes",
                Value = "5",
            });
            listItems.Add(new SelectListItem
            {
                Text = "10 Minutes",
                Value = "10",
                Selected = true
            });
            listItems.Add(new SelectListItem
            {
                Text = "15 Minutes",
                Value = "15"
            });
            listItems.Add(new SelectListItem
            {
                Text = "20 Minutes",
                Value = "20"
            });
            listItems.Add(new SelectListItem
            {
                Text = "25 Minutes",
                Value = "25"
            });

            listItems.Add(new SelectListItem
            {
                Text = "30 Minutes",
                Value = "30"
            });

            listItems.Add(new SelectListItem
            {
                Text = "1 Hour",
                Value = "60"
            });


        }
        @Html.DropDownList("refresh-dropdown", listItems, null, new { @class = "refresh-dropdown" })
    </p>
    
    <p>
        <button id="update-settings">Update Settings</button>
        <span id="update-result"></span>
    </p>    
</div>

@Html.Partial("_SuggestionFeedbackModal")
<input id="iid" type="hidden" value="-6" />
<script type="text/javascript">

    $(document).ready(function () {
        $("#update-settings").on("click", function () {
            SaveSettings();
        });

        //for now we don't want to disable until we add additional options
        //$("#enable-suggestions-ide").on("click", function () {
        //    if (!$("#enable-suggestions-ide").is(":checked")) {
        //        $("#refresh-dropdown").prop("disabled", true);
        //        $('#refresh-dropdown').css('opacity', '0.65');
        //        $('#suggestion-refresh-label').css('opacity', '0.65');
        //        $('#refresh-dropdown').css('cursor', 'not-allowed');
        //    }
        //    else
        //    {
        //        $("#refresh-dropdown").prop("disabled", false);
        //        $('#refresh-dropdown').css('opacity', '1.0');
        //        $('#suggestion-refresh-label').css('opacity', '1.0');
        //        $('#refresh-dropdown').css('cursor', 'default');
        //    }
        //});
        
        $("#refresh-dropdown option[value=@RefreshThreshold]").attr('selected', 'selected');
        @*
        if (!$("#enable-suggestions-ide").is(":checked")) {
            $("#refresh-dropdown").prop("disabled", true);
            $('#refresh-dropdown').css('opacity', '0.65');
            $('#suggestion-refresh-label').css('opacity', '0.65');
            $('#refresh-dropdown').css('cursor', 'not-allowed');
        }*@
    });

    function SaveSettings() {
        $.ajax({
            url: "/Intervention/UpdateSuggestionsSettings",
            data: { enableSuggestionsIDE: $("#enable-suggestions-ide").is(':checked'), refreshThreshold: $("#refresh-dropdown").val() },
            //dataType: "json",
            method: "POST",
            success: function (result) {
                $("#update-result").text("Settings updated successfully!").show().fadeOut(5000, "linear");
                $("#update-result").css("color", "green");
            },
            error: function (result) {
                $("#update-result").text("Settings updated failed! Please try again or contact OSBLE support for help.").show();
                $("#update-result").css("color", "red");
            }
        });
    }

</script>
